﻿using DevExpress.XtraGrid.Demos.util;
using DiaoPaiDaYin;
using DXApplicationTangche.service;
using DXApplicationTangche.UC.款式异常;
using DXApplicationTangche.UC.订单一览新.订单预览新.service;
using DXApplicationTangche.UC.货号管理.service;
using DXApplicationTangche.UC.门店下单.DTO;
using DXApplicationTangche.UC.门店下单.service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace mendian
{
    public partial class Frm设计点 : DevExpress.XtraBars.ToolbarForm.ToolbarForm
    {
        private String orderId;
        private String shopid;
        private String ogid;
        private UC设计点选择 card;
        private DTODesignPoints Dto设计点;

        private String PitemName;
        private String PitemValue;
        private bool changeOrderFlag = false;//修改订单标志
        private String styleid;//款式id修改订单用
        private List<DesignOptionDTO> designOptionDTOs;
        public Frm设计点()
        {
            InitializeComponent();
        }
        public enum Enum选择设计点类型 { 默认, 全部 }
        public Enum选择设计点类型 enum选择设计点类型;
        public Frm设计点(UC设计点选择 card, Enum选择设计点类型 enum选择设计点类型,String shopid,String ogid)
        {
            InitializeComponent();
            this.enum选择设计点类型 = enum选择设计点类型;
            this.card = card;
            this.shopid = shopid;
            this.ogid = ogid;
            this.PitemName = this.card.PitemName;
            this.PitemValue = this.card.PitemValue;
            if (this.enum选择设计点类型 == Enum选择设计点类型.全部)
            {
                this.Text = "选择全部" + this.card.PitemName;
                generatePictureLayout();
            }
            if (this.enum选择设计点类型 == Enum选择设计点类型.默认)
            {
                this.Text = "选择默认" + this.card.PitemName;
                generatePictureLayout();
            }
        }

        private void generatePictureLayout()
        {
            this.splashScreenManager.ShowWaitForm();
            this.splashScreenManager.SetWaitFormCaption("请稍后,正在加载中....");     // 标题
            this.splashScreenManager.SetWaitFormDescription("正在初始化.....");　　　　　// 信息
            this.designOptionDTOs = 下单相关Service.getDesignOption(this.PitemValue);
            this.gridControl1.DataSource = this.designOptionDTOs;
            this.splashScreenManager.CloseWaitForm();
        }

        private void tileView1_ItemClick(object sender, DevExpress.XtraGrid.Views.Tile.TileViewItemClickEventArgs e)
        {
            if (MessageBox.Show("是否选择"+ tileView1.GetRowCellValue(e.Item.RowHandle, "itemNameCn").ToString(),
        "Saving a document", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                //try
                //{
                //    this.card.build设计点(
                //        (String)tileView1.GetRowCellValue(e.Item.RowHandle, "itemNameCn")
                //        , (String)tileView1.GetRowCellValue(e.Item.RowHandle, "itemCd")
                //        , (String)tileView1.GetRowCellValue(e.Item.RowHandle, "itemValue")
                //        , (String)tileView1.GetRowCellValue(e.Item.RowHandle, "itemCd")
                //        //, (Image)tileView1.GetRowCellValue(e.Item.RowHandle, "picture")
                //        , FunctionHelper.getSSHIRT()
                //        );
                //}
                //catch { }
                try
                {
                    this.Dto设计点.build设计点(
                        (String)tileView1.GetRowCellValue(e.Item.RowHandle, "itemNameCn")
                        , (String)tileView1.GetRowCellValue(e.Item.RowHandle, "itemValue")
                        //, (Image)tileView1.GetRowCellValue(e.Item.RowHandle, "picture")
                        ,FunctionHelper.getSSHIRT()
                        );
                }
                catch { }
                if (this.changeOrderFlag == true)
                {
                    try
                    {
                        OrderService.ChangeOrder设计点(
                            this.orderId, 
                            new DTODesignPoints设计点().buildOptionName(
                                this.Dto设计点.itemCd,
                                this.Dto设计点.itemValue,
                                (String)tileView1.GetRowCellValue(e.Item.RowHandle, "itemValue"),
                                (String)tileView1.GetRowCellValue(e.Item.RowHandle, "itemNameCn")
                                )
                            );
                        //ItemService.Change设计点(this.Dto设计点, this.styleid);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                this.Close();
            }
        }

        public Frm设计点(DTODesignPoints Dto设计点, Enum选择设计点类型 enum选择设计点类型, String styleid, String shopid, String ogid,String orderId)
        {
            InitializeComponent();
            this.orderId = orderId;
            this.enum选择设计点类型 = enum选择设计点类型;
            this.Dto设计点 = Dto设计点;
            this.PitemName = Dto设计点.itemTypeNameCn;
            this.PitemValue = Dto设计点.itemValue;
            this.changeOrderFlag = true;
            this.styleid = styleid;
            this.shopid = shopid;
            this.ogid = ogid;
            this.generatePictureLayout();
        }
    }
}
